<%--
  Created by IntelliJ IDEA.
  User: Albert Lee
  Date: 2020/5/26
  Time: 16:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>个人信息</title>
</head>
<link rel="stylesheet" href="css/header.css">


<body background="resourse/bg.jpg">
<%--判断是否登录--%>
<%
    String userid=(String)session.getAttribute("userid");
//    System.out.print("Session userID="+userid);

    if (userid!=null) {
%>

<div id="header"><!--页头-->
    <spana >&emsp;巴以小记</spana>
    <br>
    <spanb >&emsp;&emsp;<%=(String)session.getAttribute("userid")%> 在线中..</spanb>
    <ul>
        <li></li>
        <li><h2 class="main" ><a class="btna" href="main.jsp">主页</a></h2></li>
        <li><h2 class="work"><a class="btna" href="addInfo.jsp">发贴</a></h2></li>
        <li><h2 class="new"><a class="btna" href="showInfo.jsp" >看贴</a></h2></li>
        <li><h2 class="comment"><a class="btna" href="showInfo.jsp" >搜索</a></h2></li>
    </ul>
</div>

<%
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");

    String comment = request.getParameter("comment");

    Connection conn = null;
    PreparedStatement stat = null;
    ResultSet rs = null;

    Class.forName("com.mysql.cj.jdbc.Driver");
    String url = "jdbc:mysql://localhost:3306/talknewsdatabase";
    String user = "root";
    String password = "123456";
    conn = DriverManager.getConnection(url,user,password);
    //    stat = conn.createStatement();
    //    rs = stat.executeQuery("select * from stu");
%>


<br>
<form action="delete_checkbox.jsp">
    <table  cellSpacing=3 >
        <tr>
            <th width="10px">
                <input type="submit" value ="×">
            </th>
            <th width="150px">编号</th>
            <th width="200px">类型</th>
            <th>标题</th>
            <th width="100px">内容</th>
            <th width="80px"></th>
            <th width="80px"></th>
        </tr>
        <%

            int lineCount;
            stat = conn.prepareStatement("select count(*) from info where user_id='" +userid +  "' and comment='" + comment + "'");
            rs = stat.executeQuery();
            rs.next();
            lineCount = rs.getInt(1);
            out.println(" <h3>一共搜索到" + lineCount + "条符合的结果</h3>");


            rs = stat.executeQuery("select * from info where user_id='" +userid +  "' and comment='" + comment + "'");

            while(rs.next()){   //输出表格内容
                Integer deleteid = rs.getInt("id");
                out.print("<tr>");
                out.println("<td>" + "<input type=\"checkbox\" name = \"delete_id\" value=\"" + deleteid + "\">" + "</td>");
        %>
                <td><%=rs.getString("id")%></td>
                <td><%=rs.getString("name")%></td>
                <td><%=rs.getString("title")%></td>
                <td  align="center" ><a href="select_for_id.jsp?id=<%=rs.getString("id")%>">查看内容</a></td>

                <td  align="center" width="40px"><a href="delete.jsp?id=<%=rs.getString("id") %>">删除</a></td>
                <td  align="center" width="40px"><a href="update.jsp?id=<%=rs.getString("id") %>">修改</a></td>
                </tr>
        <%
            }
        %>
    </table>



<%
    if(rs != null) {
        rs.close();
        rs = null;
    }
    if(stat != null) {
        stat.close();
        stat = null;
    }
    if(conn != null) {
        conn.close();
        conn = null;
    }
%>

<%
    } else {
        out.print("<script>alert('未成功登录！');" +
                "window.location='http://localhost:8080/index.html';</script>");
    }
%>

</body>
</html>